<%@ page import="com.scalar.chiptrack.utils.ConfigManager, java.util.Calendar"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<chiptrack:checkLogon sourcePage="/graphReport.do?action=cycleTimeReport" />
<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel=stylesheet>
<SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></SCRIPT>
<SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></SCRIPT>

<SCRIPT language="JavaScript">

var dateElement = "";
function openCalendar(dateValue)
{
    dateElement = dateValue;
    newWindow = window.open('<%=chipTracContext%>/jsp/includes/calendar.html','optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=180,height=440,resizable=no');
    newWindow.moveTo(550,180);
    newWindow.focus();
}
function assignDate(passedValue)
{
    dateElement.value=passedValue;
    window.focus();
}

function selectBaseProduct()
{
    var pa=document.getElementById("errors");
    pa.innerHTML = "";
    var baseProductId = document.graphReportForm.baseProductId.value;

    if ( document.graphReportForm.processType.value == '' || document.graphReportForm.processType.value == '0' )
    {
        pa.innerHTML = "<li> Please select Process Type";
        document.graphReportForm.baseProductId.value = '0';
        return;
    }
    document.graphReportForm.action='<%=chipTracContext%>/graphReport.do?action=cycleTimeReport';
	document.graphReportForm.submit();
}

function getProductsForProcess()
{
	document.graphReportForm.action="<%=chipTracContext%>/graphReport.do?action=cycleTimeReport";
    document.graphReportForm.baseProductId.value=0;
    document.graphReportForm.vendorName.value = 0;
    document.graphReportForm.submit();
}

function validateFromAndToDates()
{
    var formdoc = document.graphReportForm;
    errMsg = '';

    var pa	= document.getElementById("errors");

    if(chkDate(formdoc.fromDate.value,'From-Date','Y') == false)
    {
        pa.innerHTML = errMsg;
        formdoc.fromDate.focus();
        return false;
    }

    if(chkDate(formdoc.toDate.value,'To-Date','Y') == false)
    {
        pa.innerHTML = errMsg;
        formdoc.toDate.focus();
        return false;
    }

    if(formdoc.fromDate.value!='' && formdoc.toDate.value!='')
    {
        if (!validateDateOut(formatDateAsMMDDYYYY(formdoc.fromDate.value),formatDateAsMMDDYYYY(formdoc.toDate.value)))
        {
            pa.innerHTML = "To Date cannot be less than From Date";
            formdoc.toDate.focus();
            return false;
        }
    }
    return true;
}

function submitReport(reportType)
{
    var pa=document.getElementById("errors");
    pa.innerHTML = "";

    var form = document.graphReportForm;
    if ( document.graphReportForm.processType.value == '' || document.graphReportForm.processType.value == '0' )
    {
        pa.innerHTML = "<li> Please select Process Type";
        return;
    }
    var success;
    success = true;
    success = validateFromAndToDates();
    if(success == false)
    {
       return;
    }

    /* var partNumberObj =form.processStepId;
    var processstepId = "";
    var count = 0;
    for( var i = 0; i < partNumberObj.length; i++ )
    {
        if( partNumberObj.options[i].selected )
        {
            count++;
            if ( processstepId != '' )
            {
                processstepId = processstepId + "," + partNumberObj.options[i].value;
            }
            else
            {
                processstepId = partNumberObj.options[i].value;
                if( partNumberObj.options[i].value == '0' )
                {
                    break;
                }
            }
        }
    }
    if ( processstepId == '')
    {
        processstepId = "0";
    }
    if( count > 10)
    {
        pa.innerHTML = "<li>Please select upto 10 Products only";
        return false;
    }
    else
    {
        form.processStepId.value = processstepId;
    }*/

    document.graphReportForm.action="<%=chipTracContext%>/graphReport.do?action=cycleTimeXlsReport";
    document.graphReportForm.submit();

}

function loadProducts()
{
	document.graphReportForm.action="<%=chipTracContext%>/graphReport.do?action=cycleTimeReport";
	document.graphReportForm.submit();
}

function clearErrors()
{
    var pa=document.getElementById("errors");
    pa.innerHTML = "";
}

</script>
</HEAD>
<BODY bgColor="#ffffff" leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">

<!-- Top Header Start-->
<%@ include file="/jsp/includes/header.jsp" %>
<!-- Top Header End-->

<TABLE cellSpacing=0 cellPadding=0 width="100%" border="0">
    <TR>
        <td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
            <!-- Side Navigation start -->
            <%@ include file="/jsp/engineering/engg_report_menu.jsp" %>
            <!-- end of the side navigations -->
        </td>
        <TD bgcolor="#ffffff"><IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
        <TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
        <html:form name="graphReportForm" action="/graphReport.do?action=cycleTimeReport" type="com.scalar.chiptrack.engineering.forms.GraphReportForm">
        <TD valign="top" width="100%">
            <table border="0" width="100%" align="center">
                <tr><td colspan="6" width="100%"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
                <tr><td colspan="6" width="100%"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
                <%--<tr><td colspan="6" width="100%"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>--%>
                <tr>
                    <TD width="100%" COLSPAN="6">
                        <TABLE width="100%" align=right border="0">
                            <TR>
                                <TD width="15%">&nbsp;</TD>
                                <TD width="65%" align="center" class="NArialW">Cycle Time Report</TD>
                                <TD width="20%">&nbsp;</TD>
                            </TR>
                        </TABLE>
                    </TD>
                </tr>
                <tr><td colspan="6" width="100%"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
                <tr>
                    <td width="10%">&nbsp;</td>
                    <td width="85%" colspan="5" align="left">
                        <b><font face="Verdana" size="-5" align="center" color="#ff0000" id="errors"></font></b>&nbsp;
                    </td>
                </tr>
                <TR>
                    <td width="2%">&nbsp;</td>
                    <TD width="20%" class=NArialL valign = 'top' align = "right">Process Type<font color=red>*</font> :</TD>
                    <TD width="20%" class=NArialL>
                        <nested:select property="processType" styleClass="txfield" style= "width:170px" onchange="getProductsForProcess()">
                            <html:option value="0">Select Process Type</html:option>
                            <nested:options collection="processList" property="value" labelProperty="label"/>
                        </nested:select>
                    </TD>
                    <TD width="3%">&nbsp;</TD>
                    <TD width="10%" class=NArialL>Vendors:</TD>
                    <TD width="45%"align="left" class=NArialL><nested:select property="vendorName" style= "width:170px"  styleClass="txfield">
                            <html:option value="0">All Vendors</html:option>
                            <html:options collection="vendorList" property="label" labelProperty="label"/>
                        </nested:select>
                    </TD>
                </TR>
                <tr><td colspan="6" width="100%"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>

                <TR>
                    <td width="2%">&nbsp;</td>
                    <TD width="20%" class="NArialL" valign = 'top' align = "right">Base Product :</TD>
                    <TD width="20%" class="NArialL" valign="top">
                        <nested:select property="baseProductId" styleClass="txfield" style= "width:170px" onchange="selectBaseProduct()" >
                            <html:option value="0">All Base Products</html:option>
                            <html:options collection="baseProductList" property="value" labelProperty="label"/>
                        </nested:select>
                    </TD>
                    <TD width="3%">&nbsp;</TD>
                    <TD width="10%" class="NArialL" valign="top">Products:</TD>
                    <TD width="45%" class="NArialL" valign="top">
                        <nested:select property="processStepId" styleClass="txfield" style= "width:170px">
                            <html:option value="0">All Products</html:option>
                            <html:options collection="partNumberList" property="value" labelProperty="label"/>
                        </nested:select>
                    </TD>
                </TR>
                <tr><td colspan="6" width="100%"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
                <TR>
                    <TD width="2%">&nbsp;</TD>
                    <TD width="20%" class="NArialL" valign = 'top' align = "right">From Date<font color=red>*</font> :</TD>
                    <TD width="20%" class="NArialL" valign = 'top'>
                        <nested:text property="fromDate" size="12" styleClass="txfield"/>
                        <a href="javascript:openCalendar(document.graphReportForm.fromDate)"onmouseover="window.status='Click to Select From Date';return true"onmouseout="window.status='';return true"title="Click here to Select From Date">
                            <img border="0" src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=18 width=18>
                        </a>
                    </TD>
                    <TD width="3%">&nbsp;</TD>
                    <TD width="10%" class="NArialL" valign = 'top'>To Date<font color=red>*</font> :</TD>
                    <TD width="45%" class="NArialL" valign = 'top'>
                        <nested:text property="toDate" size="12" styleClass="txfield"/>
                        <a href="javascript:openCalendar(document.graphReportForm.toDate)"onmouseover="window.status='Click to Select From Date';return true"onmouseout="window.status='';return true"title="Click here to Select From Date">
                            <img border="0" src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=18 width=18>
                        </a>
                    </TD>
                    <TD width="15%" >&nbsp;</TD>
                </TR>
                <tr><td colspan="6" width="100%"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
                <tr>
                        <td colspan=5>&nbsp;</td>
                        <td colspan=1 class="NArialL">
                            <a class="leftsection" href="javascript:submitReport(2)" onMouseOver="window.status='Click here to Export to Excel';return true" onMouseOut="window.status='';return true" title='Click here to Export to Excel' >Export to Excel</a>
                        </td>
                    </tr>
                <tr>
                    <td colspan=1 valign="top">&nbsp;</td>
                    <TD colspan="4" align=right valign="top">
                    <a href="javascript:submitReport(1);"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/submit.gif" width="53" height="17" onmouseover="window.status='Click to Generate Transaction Report';return true" onmouseout="window.status='';return true" title='Click to Generate Transaction Report'></a>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <a href="javascript:document.graphReportForm.reset();"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17" onmouseover="window.status='Click to reset search';return true" onmouseout="window.status='';return true" title="Click here to reset search"></a>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </TD>
                <td colspan=1 valign="top">&nbsp;</td>
                </tr>
            </table>
            <BR><BR><BR>
            </html:form>
        </TD>
        <TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
    </TR>
</TABLE>
<!-- Footer starts here -->
<%@ include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->
</BODY>
</HTML>
